#include "selection.h"
#include <QDebug>

Selection::Selection(QObject *parent) : QObject(parent)
{

}

void Selection::select(Cell *cell)
{
    this->prevCell = this->cell;
    this->cell = cell;
    if (prevCell != nullptr && cell == prevCell){
        setSelected(!selected);
    }else{
        setSelected(true);
    }

    if (selected && prevSelected){
        emit move(prevCell, cell);
    }
}

Cell *Selection::getCell()
{
    return cell;
}

bool Selection::isSelected()
{
    return selected;
}

void Selection::unselect()
{
    setSelected(false);
}

void Selection::setSelected(bool selected)
{
    prevSelected = this->selected;
    this->selected = selected;
}
